#ifndef CAPTURE_PLATFORM_H_
#define CAPTURE_PLATFORM_H_

#include <stdint.h>
#include <sys/platform.h>
#include <sys/slog.h>
#include <vcapture/capture.h>

__BEGIN_DECLS

typedef enum _captrure_device_type {
	/* 0 */ CAPTURE_DEV_TYPE_UNKNOWN,
	/* 1 */ CAPTURE_DEV_TYPE_SOC,
	/* 2 */ CAPTURE_DEV_TYPE_DECODER_CAMERA,
	/* 3 */ CAPTURE_DEV_TYPE_BOARD,
} captrure_device_type_t;

typedef int capture_log_context_t;

extern void capture_log_init(void);
extern capture_log_context_t capture_log_create_context(captrure_device_type_t type, const char *name);
extern void capture_log_destroy_context(capture_log_context_t context);
extern void capture_log_set_verbose(capture_log_context_t context, uint32_t verbose);
extern void capture_log(capture_log_context_t context, int level, int severity, const char *fmt, ...);

#if 1
#define capture_log_debug(cxt, level, fmt, ...) \
	capture_log(cxt, level, _SLOG_INFO, fmt, ##__VA_ARGS__)

#define capture_log_error(cxt, fmt, ...) \
	capture_log(cxt, 0, _SLOG_ERROR, fmt, ##__VA_ARGS__)
#else
#define capture_log_debug(cxt, level, fmt, ...) \
	printf(fmt, ##__VA_ARGS__)

#define capture_log_error(cxt, fmt, ...) \
	printf(fmt, ##__VA_ARGS__)
#endif

typedef struct _capture_api {
	int (*capture_create_buffers)(capture_context_t context, uint32_t property);
	capture_context_t (*capture_create_context)(uint32_t flags);
	void (*capture_destroy_context)(capture_context_t context);
	int (*capture_get_frame)(capture_context_t context, uint64_t timeout, uint32_t flags);
	int (*capture_get_property_i)(capture_context_t context, uint32_t prop, int32_t *value);
	int (*capture_get_property_p)(capture_context_t context, uint32_t prop, void **value);
	int (*capture_is_property)(capture_context_t context, uint32_t prop);
	int (*capture_put_buffer)(capture_context_t ctx, uint32_t idx, uint32_t flags);
	int (*capture_release_frame)(capture_context_t context, uint32_t idx);
	int (*capture_set_property_i)(capture_context_t context, uint32_t prop, int32_t value);
	int (*capture_set_property_p)(capture_context_t context, uint32_t prop, void *value);
	int (*capture_update)(capture_context_t context, uint32_t flags);
	int (*capture_get_reg)(capture_context_t context, uint32_t page, uint32_t reg, uint32_t* data);
} capture_api_t;

typedef struct _capture_device {
	void *ctx;
	capture_api_t api;
} capture_device_t;

extern int capture_get_device_api(const char *lib_name, captrure_device_type_t dev_type, capture_api_t *api);

extern int capture_i2c_open(const char *path);
extern int capture_i2c_close(int fd);
extern int capture_i2c_set_speed(int fd, uint32_t speed);
extern int capture_i2c_rd(int fd, uint32_t dev_addr, uint8_t reg_addr, uint8_t *data);
extern int capture_i2c_wr(int fd, uint32_t dev_addr, uint8_t reg_addr, uint8_t data);
extern int capture_i2c_dump(int fd, uint32_t dev_addr, uint8_t reg_addr, uint8_t *data, uint32_t size);
extern const char *capture_log_prop_str(uint32_t id);

__END_DECLS

#endif /* CAPTURE_PLATFORM_H_ */
